//
//  HSProtocolManager.m
//  AFNetworking
//
//  Created by huang on 2018/8/22.
//

#import "HSProtocolManager.h"

@interface HSProtocolManager ()

@property (nonatomic, strong) NSMutableDictionary *serviceProvideSource;

@end

@implementation HSProtocolManager

+ (HSProtocolManager *)shareInstance
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (instancetype)init
{
    if (self = [super init]) {
        _serviceProvideSource = [[NSMutableDictionary alloc] init];
    }
    return self;
}

+ (void)registServiceProvide:(id)provide forProtocol:(Protocol *)protocol
{
    if (provide == nil || protocol == nil) {
        return;
    }
    
    [[self shareInstance].serviceProvideSource setObject:provide forKey:NSStringFromProtocol(protocol)];
}

+ (id)serviceProvideForProtocol:(Protocol *)protocol
{
    return [[self shareInstance].serviceProvideSource objectForKey:NSStringFromProtocol(protocol)];
}

#pragma mark - setting or getting
- (NSMutableDictionary *)serviceProvideSource
{
    if (!_serviceProvideSource) {
        _serviceProvideSource = [[NSMutableDictionary alloc] init];
    }
    return _serviceProvideSource;
}

@end
